<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
 <head>
  <title>chetrf.f</title>
 <meta name="generator" content="emacs 21.3.1; htmlfontify 0.20">
<style type="text/css"><!-- 
body { background: rgb(255, 255, 255);  color: rgb(0, 0, 0);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: none; }
span.default   { background: rgb(255, 255, 255);  color: rgb(0, 0, 0);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: none; }
span.default a { background: rgb(255, 255, 255);  color: rgb(0, 0, 0);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: underline; }
span.string   { color: rgb(188, 143, 143);  background: rgb(255, 255, 255);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: none; }
span.string a { color: rgb(188, 143, 143);  background: rgb(255, 255, 255);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: underline; }
span.comment   { color: rgb(178, 34, 34);  background: rgb(255, 255, 255);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: none; }
span.comment a { color: rgb(178, 34, 34);  background: rgb(255, 255, 255);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: underline; }
 --></style>

 </head>
  <body>

<pre>
      SUBROUTINE <a name="CHETRF.1"></a><a href="chetrf.f.html#CHETRF.1">CHETRF</a>( UPLO, N, A, LDA, IPIV, WORK, LWORK, INFO )
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  -- LAPACK routine (version 3.1) --
</span><span class="comment">*</span><span class="comment">     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
</span><span class="comment">*</span><span class="comment">     November 2006
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     .. Scalar Arguments ..
</span>      CHARACTER          UPLO
      INTEGER            INFO, LDA, LWORK, N
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. Array Arguments ..
</span>      INTEGER            IPIV( * )
      COMPLEX            A( LDA, * ), WORK( * )
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  Purpose
</span><span class="comment">*</span><span class="comment">  =======
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  <a name="CHETRF.19"></a><a href="chetrf.f.html#CHETRF.1">CHETRF</a> computes the factorization of a complex Hermitian matrix A
</span><span class="comment">*</span><span class="comment">  using the Bunch-Kaufman diagonal pivoting method.  The form of the
</span><span class="comment">*</span><span class="comment">  factorization is
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     A = U*D*U**H  or  A = L*D*L**H
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  where U (or L) is a product of permutation and unit upper (lower)
</span><span class="comment">*</span><span class="comment">  triangular matrices, and D is Hermitian and block diagonal with 
</span><span class="comment">*</span><span class="comment">  1-by-1 and 2-by-2 diagonal blocks.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  This is the blocked version of the algorithm, calling Level 3 BLAS.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  Arguments
</span><span class="comment">*</span><span class="comment">  =========
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  UPLO    (input) CHARACTER*1
</span><span class="comment">*</span><span class="comment">          = 'U':  Upper triangle of A is stored;
</span><span class="comment">*</span><span class="comment">          = 'L':  Lower triangle of A is stored.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  N       (input) INTEGER
</span><span class="comment">*</span><span class="comment">          The order of the matrix A.  N &gt;= 0.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  A       (input/output) COMPLEX array, dimension (LDA,N)
</span><span class="comment">*</span><span class="comment">          On entry, the Hermitian matrix A.  If UPLO = 'U', the leading
</span><span class="comment">*</span><span class="comment">          N-by-N upper triangular part of A contains the upper
</span><span class="comment">*</span><span class="comment">          triangular part of the matrix A, and the strictly lower
</span><span class="comment">*</span><span class="comment">          triangular part of A is not referenced.  If UPLO = 'L', the
</span><span class="comment">*</span><span class="comment">          leading N-by-N lower triangular part of A contains the lower
</span><span class="comment">*</span><span class="comment">          triangular part of the matrix A, and the strictly upper
</span><span class="comment">*</span><span class="comment">          triangular part of A is not referenced.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">          On exit, the block diagonal matrix D and the multipliers used
</span><span class="comment">*</span><span class="comment">          to obtain the factor U or L (see below for further details).
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  LDA     (input) INTEGER
</span><span class="comment">*</span><span class="comment">          The leading dimension of the array A.  LDA &gt;= max(1,N).
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  IPIV    (output) INTEGER array, dimension (N)
</span><span class="comment">*</span><span class="comment">          Details of the interchanges and the block structure of D.
</span><span class="comment">*</span><span class="comment">          If IPIV(k) &gt; 0, then rows and columns k and IPIV(k) were
</span><span class="comment">*</span><span class="comment">          interchanged and D(k,k) is a 1-by-1 diagonal block.
</span><span class="comment">*</span><span class="comment">          If UPLO = 'U' and IPIV(k) = IPIV(k-1) &lt; 0, then rows and
</span><span class="comment">*</span><span class="comment">          columns k-1 and -IPIV(k) were interchanged and D(k-1:k,k-1:k)
</span><span class="comment">*</span><span class="comment">          is a 2-by-2 diagonal block.  If UPLO = 'L' and IPIV(k) =
</span><span class="comment">*</span><span class="comment">          IPIV(k+1) &lt; 0, then rows and columns k+1 and -IPIV(k) were
</span><span class="comment">*</span><span class="comment">          interchanged and D(k:k+1,k:k+1) is a 2-by-2 diagonal block.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  WORK    (workspace/output) COMPLEX array, dimension (MAX(1,LWORK))
</span><span class="comment">*</span><span class="comment">          On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  LWORK   (input) INTEGER
</span><span class="comment">*</span><span class="comment">          The length of WORK.  LWORK &gt;=1.  For best performance
</span><span class="comment">*</span><span class="comment">          LWORK &gt;= N*NB, where NB is the block size returned by <a name="ILAENV.71"></a><a href="ilaenv.f.html#ILAENV.1">ILAENV</a>.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  INFO    (output) INTEGER
</span><span class="comment">*</span><span class="comment">          = 0:  successful exit
</span><span class="comment">*</span><span class="comment">          &lt; 0:  if INFO = -i, the i-th argument had an illegal value
</span><span class="comment">*</span><span class="comment">          &gt; 0:  if INFO = i, D(i,i) is exactly zero.  The factorization
</span><span class="comment">*</span><span class="comment">                has been completed, but the block diagonal matrix D is
</span><span class="comment">*</span><span class="comment">                exactly singular, and division by zero will occur if it
</span><span class="comment">*</span><span class="comment">                is used to solve a system of equations.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  Further Details
</span><span class="comment">*</span><span class="comment">  ===============
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  If UPLO = 'U', then A = U*D*U', where
</span><span class="comment">*</span><span class="comment">     U = P(n)*U(n)* ... *P(k)U(k)* ...,
</span><span class="comment">*</span><span class="comment">  i.e., U is a product of terms P(k)*U(k), where k decreases from n to
</span><span class="comment">*</span><span class="comment">  1 in steps of 1 or 2, and D is a block diagonal matrix with 1-by-1
</span><span class="comment">*</span><span class="comment">  and 2-by-2 diagonal blocks D(k).  P(k) is a permutation matrix as
</span><span class="comment">*</span><span class="comment">  defined by IPIV(k), and U(k) is a unit upper triangular matrix, such
</span><span class="comment">*</span><span class="comment">  that if the diagonal block D(k) is of order s (s = 1 or 2), then
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">             (   I    v    0   )   k-s
</span><span class="comment">*</span><span class="comment">     U(k) =  (   0    I    0   )   s
</span><span class="comment">*</span><span class="comment">             (   0    0    I   )   n-k
</span><span class="comment">*</span><span class="comment">                k-s   s   n-k
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  If s = 1, D(k) overwrites A(k,k), and v overwrites A(1:k-1,k).
</span><span class="comment">*</span><span class="comment">  If s = 2, the upper triangle of D(k) overwrites A(k-1,k-1), A(k-1,k),
</span><span class="comment">*</span><span class="comment">  and A(k,k), and v overwrites A(1:k-2,k-1:k).
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  If UPLO = 'L', then A = L*D*L', where
</span><span class="comment">*</span><span class="comment">     L = P(1)*L(1)* ... *P(k)*L(k)* ...,
</span><span class="comment">*</span><span class="comment">  i.e., L is a product of terms P(k)*L(k), where k increases from 1 to
</span><span class="comment">*</span><span class="comment">  n in steps of 1 or 2, and D is a block diagonal matrix with 1-by-1
</span><span class="comment">*</span><span class="comment">  and 2-by-2 diagonal blocks D(k).  P(k) is a permutation matrix as
</span><span class="comment">*</span><span class="comment">  defined by IPIV(k), and L(k) is a unit lower triangular matrix, such
</span><span class="comment">*</span><span class="comment">  that if the diagonal block D(k) is of order s (s = 1 or 2), then
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">             (   I    0     0   )  k-1
</span><span class="comment">*</span><span class="comment">     L(k) =  (   0    I     0   )  s
</span><span class="comment">*</span><span class="comment">             (   0    v     I   )  n-k-s+1
</span><span class="comment">*</span><span class="comment">                k-1   s  n-k-s+1
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  If s = 1, D(k) overwrites A(k,k), and v overwrites A(k+1:n,k).
</span><span class="comment">*</span><span class="comment">  If s = 2, the lower triangle of D(k) overwrites A(k,k), A(k+1,k),
</span><span class="comment">*</span><span class="comment">  and A(k+1,k+1), and v overwrites A(k+2:n,k:k+1).
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  =====================================================================
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     .. Local Scalars ..
</span>      LOGICAL            LQUERY, UPPER
      INTEGER            IINFO, IWS, J, K, KB, LDWORK, LWKOPT, NB, NBMIN
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. External Functions ..
</span>      LOGICAL            <a name="LSAME.125"></a><a href="lsame.f.html#LSAME.1">LSAME</a>
      INTEGER            <a name="ILAENV.126"></a><a href="ilaenv.f.html#ILAENV.1">ILAENV</a>
      EXTERNAL           <a name="LSAME.127"></a><a href="lsame.f.html#LSAME.1">LSAME</a>, <a name="ILAENV.127"></a><a href="ilaenv.f.html#ILAENV.1">ILAENV</a>
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. External Subroutines ..
</span>      EXTERNAL           <a name="CHETF2.130"></a><a href="chetf2.f.html#CHETF2.1">CHETF2</a>, <a name="CLAHEF.130"></a><a href="clahef.f.html#CLAHEF.1">CLAHEF</a>, <a name="XERBLA.130"></a><a href="xerbla.f.html#XERBLA.1">XERBLA</a>
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. Intrinsic Functions ..
</span>      INTRINSIC          MAX
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. Executable Statements ..
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     Test the input parameters.
</span><span class="comment">*</span><span class="comment">
</span>      INFO = 0
      UPPER = <a name="LSAME.140"></a><a href="lsame.f.html#LSAME.1">LSAME</a>( UPLO, <span class="string">'U'</span> )
      LQUERY = ( LWORK.EQ.-1 )
      IF( .NOT.UPPER .AND. .NOT.<a name="LSAME.142"></a><a href="lsame.f.html#LSAME.1">LSAME</a>( UPLO, <span class="string">'L'</span> ) ) THEN
         INFO = -1
      ELSE IF( N.LT.0 ) THEN
         INFO = -2
      ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
         INFO = -4
      ELSE IF( LWORK.LT.1 .AND. .NOT.LQUERY ) THEN
         INFO = -7
      END IF
<span class="comment">*</span><span class="comment">
</span>      IF( INFO.EQ.0 ) THEN
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">        Determine the block size
</span><span class="comment">*</span><span class="comment">
</span>         NB = <a name="ILAENV.156"></a><a href="ilaenv.f.html#ILAENV.1">ILAENV</a>( 1, <span class="string">'<a name="CHETRF.156"></a><a href="chetrf.f.html#CHETRF.1">CHETRF</a>'</span>, UPLO, N, -1, -1, -1 )
         LWKOPT = N*NB
         WORK( 1 ) = LWKOPT
      END IF
<span class="comment">*</span><span class="comment">
</span>      IF( INFO.NE.0 ) THEN
         CALL <a name="XERBLA.162"></a><a href="xerbla.f.html#XERBLA.1">XERBLA</a>( <span class="string">'<a name="CHETRF.162"></a><a href="chetrf.f.html#CHETRF.1">CHETRF</a>'</span>, -INFO )
         RETURN
      ELSE IF( LQUERY ) THEN
         RETURN
      END IF
<span class="comment">*</span><span class="comment">
</span>      NBMIN = 2
      LDWORK = N
      IF( NB.GT.1 .AND. NB.LT.N ) THEN
         IWS = LDWORK*NB
         IF( LWORK.LT.IWS ) THEN
            NB = MAX( LWORK / LDWORK, 1 )
            NBMIN = MAX( 2, <a name="ILAENV.174"></a><a href="ilaenv.f.html#ILAENV.1">ILAENV</a>( 2, <span class="string">'<a name="CHETRF.174"></a><a href="chetrf.f.html#CHETRF.1">CHETRF</a>'</span>, UPLO, N, -1, -1, -1 ) )
         END IF
      ELSE
         IWS = 1
      END IF
      IF( NB.LT.NBMIN )
     $   NB = N
<span class="comment">*</span><span class="comment">
</span>      IF( UPPER ) THEN
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">        Factorize A as U*D*U' using the upper triangle of A
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">        K is the main loop index, decreasing from N to 1 in steps of
</span><span class="comment">*</span><span class="comment">        KB, where KB is the number of columns factorized by <a name="CLAHEF.187"></a><a href="clahef.f.html#CLAHEF.1">CLAHEF</a>;
</span><span class="comment">*</span><span class="comment">        KB is either NB or NB-1, or K for the last block
</span><span class="comment">*</span><span class="comment">
</span>         K = N
   10    CONTINUE
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">        If K &lt; 1, exit from loop
</span><span class="comment">*</span><span class="comment">
</span>         IF( K.LT.1 )
     $      GO TO 40
<span class="comment">*</span><span class="comment">
</span>         IF( K.GT.NB ) THEN
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">           Factorize columns k-kb+1:k of A and use blocked code to
</span><span class="comment">*</span><span class="comment">           update columns 1:k-kb
</span><span class="comment">*</span><span class="comment">
</span>            CALL <a name="CLAHEF.203"></a><a href="clahef.f.html#CLAHEF.1">CLAHEF</a>( UPLO, K, NB, KB, A, LDA, IPIV, WORK, N, IINFO )
         ELSE
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">           Use unblocked code to factorize columns 1:k of A
</span><span class="comment">*</span><span class="comment">
</span>            CALL <a name="CHETF2.208"></a><a href="chetf2.f.html#CHETF2.1">CHETF2</a>( UPLO, K, A, LDA, IPIV, IINFO )
            KB = K
         END IF
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">        Set INFO on the first occurrence of a zero pivot
</span><span class="comment">*</span><span class="comment">
</span>         IF( INFO.EQ.0 .AND. IINFO.GT.0 )
     $      INFO = IINFO
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">        Decrease K and return to the start of the main loop
</span><span class="comment">*</span><span class="comment">
</span>         K = K - KB
         GO TO 10
<span class="comment">*</span><span class="comment">
</span>      ELSE
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">        Factorize A as L*D*L' using the lower triangle of A
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">        K is the main loop index, increasing from 1 to N in steps of
</span><span class="comment">*</span><span class="comment">        KB, where KB is the number of columns factorized by <a name="CLAHEF.227"></a><a href="clahef.f.html#CLAHEF.1">CLAHEF</a>;
</span><span class="comment">*</span><span class="comment">        KB is either NB or NB-1, or N-K+1 for the last block
</span><span class="comment">*</span><span class="comment">
</span>         K = 1
   20    CONTINUE
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">        If K &gt; N, exit from loop
</span><span class="comment">*</span><span class="comment">
</span>         IF( K.GT.N )
     $      GO TO 40
<span class="comment">*</span><span class="comment">
</span>         IF( K.LE.N-NB ) THEN
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">           Factorize columns k:k+kb-1 of A and use blocked code to
</span><span class="comment">*</span><span class="comment">           update columns k+kb:n
</span><span class="comment">*</span><span class="comment">
</span>            CALL <a name="CLAHEF.243"></a><a href="clahef.f.html#CLAHEF.1">CLAHEF</a>( UPLO, N-K+1, NB, KB, A( K, K ), LDA, IPIV( K ),
     $                   WORK, N, IINFO )
         ELSE
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">           Use unblocked code to factorize columns k:n of A
</span><span class="comment">*</span><span class="comment">
</span>            CALL <a name="CHETF2.249"></a><a href="chetf2.f.html#CHETF2.1">CHETF2</a>( UPLO, N-K+1, A( K, K ), LDA, IPIV( K ), IINFO )
            KB = N - K + 1
         END IF
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">        Set INFO on the first occurrence of a zero pivot
</span><span class="comment">*</span><span class="comment">
</span>         IF( INFO.EQ.0 .AND. IINFO.GT.0 )
     $      INFO = IINFO + K - 1
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">        Adjust IPIV
</span><span class="comment">*</span><span class="comment">
</span>         DO 30 J = K, K + KB - 1
            IF( IPIV( J ).GT.0 ) THEN
               IPIV( J ) = IPIV( J ) + K - 1
            ELSE
               IPIV( J ) = IPIV( J ) - K + 1
            END IF
   30    CONTINUE
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">        Increase K and return to the start of the main loop
</span><span class="comment">*</span><span class="comment">
</span>         K = K + KB
         GO TO 20
<span class="comment">*</span><span class="comment">
</span>      END IF
<span class="comment">*</span><span class="comment">
</span>   40 CONTINUE
      WORK( 1 ) = LWKOPT
      RETURN
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     End of <a name="CHETRF.279"></a><a href="chetrf.f.html#CHETRF.1">CHETRF</a>
</span><span class="comment">*</span><span class="comment">
</span>      END

</pre>

 </body>
</html>
